<?php

/**
 * Wave Framework <http://www.waveframework.com>
 * View Controller
 *
 * Wave Framework comes with a View Controller and a translations system that is used to build 
 * a website on Wave Framework. This View Controller is entirely optional and can be removed 
 * from a system if you plan to implement your own View Controller or simply use Wave Framework 
 * for API, without a website.
 *
 * @package    Tools
 * @author     Kristo Vaher <kristo@waher.net>
 * @copyright  Copyright (c) 2012, Kristo Vaher
 * @license    GNU Lesser General Public License Version 3
 * @tutorial   /doc/pages/guide_view.htm
 * @since      1.0.0
 * @version    3.6.9
 */

class WWW_controller_adminuser extends WWW_Factory {

	/**
	 * This method is called by Data Handler to render View contents based on values from 
	 * URL Controller.
	 *
	 * @param array $input input data sent to controller
	 * @input mixed input data from URL Controller output
	 * @return null
	 */
	  
	public function create_adminuser($data)
	{	
		//echo "<pre>";print_r($data);exit;
		$reason=array();
		if($data['first_name']=='')
		{
			$reason['first_nameerror']="First Name should contain some value";
			$status="fail";
		}
		if($data['middle_name']=='')
		{
			$reason['middle_nameerror']="Middle Name should contain some value";
			$status="fail";
		}
		if($data['last_name']=='')
		{
			$reason['last_nameerror']="Last Name should contain some value";
			$status="fail";
		}
		if($data['email']=='')
		{
			$reason['sequenceerror']="Email should contain some value";
			$status="fail";
		}
		if($data['user_id']=='')
		{
			$reason['user_iderror']="Userid should contain some value";
			$status="fail";
		}
		if($data['password']=='')
		{
			$reason['passworderror']="password should contain some value";
			$status="fail";
		}
		if($data['role_id']=='')
		{
			$reason['role_iderror']="Select the Role";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('adminuser');
		$result=$model->create_adminuser($data);
		//print_r($result);exit;
		return $this->resultTrue('result',$result);	
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function login($data)
	{
		if($data['user_id']=='')
		{
			$reason['user_iderror']="user id should contain some value";
			$status="fail";
		}
		if($data['password']=='')
		{
			$reason['passworderror']="password should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('adminuser');
		$result=$model->login($data);
		//print_r($result);exit;
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function edit_adminuser($data)
	{
		if($data['first_name']=='')
		{
			$reason['first_nameerror']="First Name should contain some value";
			$status="fail";
		}
		if($data['middle_name']=='')
		{
			$reason['middle_nameerror']="Middle Name should contain some value";
			$status="fail";
		}
		if($data['last_name']=='')
		{
			$reason['last_nameerror']="Last Name should contain some value";
			$status="fail";
		}
		if($data['email']=='')
		{
			$reason['sequenceerror']="Email should contain some value";
			$status="fail";
		}
		if($data['user_id']=='')
		{
			$reason['user_iderror']="Userid should contain some value";
			$status="fail";
		}
		if($data['password']=='')
		{
			$reason['passworderror']="password should contain some value";
			$status="fail";
		}
		if($data['role_id']=='')
		{
			$reason['role_iderror']="Select the Role";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('adminuser');
		$result=$model->edit_adminuser($data);
		//print_r($result);exit;
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function delete_adminuser($data){		
		$model=$this->getModel('adminuser');
		$deleted_info = $model->delete_adminuser($data);
		return $this->resultTrue('Delete modules Info',$deleted_info);
	}
		public function get_adminuser_roles()
	{	//print_r("hello world");exit;
		$model=$this->getModel('adminuser');
		$result=$model->get_adminuser_roles();
		//print_r($result);exit;
		return $this->resultTrue('result',$result);
	}
	public function get_adminuser($data)
	{	
		$model=$this->getModel('adminuser');
		$result=$model->get_adminuser($data);
		//print_r($result);exit;
		return $this->resultTrue('result',$result);
	}
	public function all_adminusers($data){	
		$model=$this->getModel('adminuser');
		$modules_info = $model->all_adminusers($data);	
		return $this->resultTrue('All modules',$modules_info);		
	}
	
	
}

?>